package com.sthz.facepay.mapper;

import com.sthz.facepay.model.Cash;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

public interface CashMapper {
    @Delete({
        "delete from st_cash",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into st_cash (id, aid, ",
        "cash_money, cash_time, ",
        "state, reviewer, ",
        "reason)",
        "values (#{id,jdbcType=INTEGER}, #{aid,jdbcType=INTEGER}, ",
        "#{cash_money,jdbcType=DOUBLE}, #{cash_time,jdbcType=TIMESTAMP}, ",
        "#{state,jdbcType=TINYINT}, #{reviewer,jdbcType=VARCHAR}, ",
        "#{reason,jdbcType=VARCHAR})"
    })
    int insert(Cash record);

    @InsertProvider(type=CashSqlProvider.class, method="insertSelective")
    int insertSelective(Cash record);

    @Select({
        "select",
        "id, aid, cash_money, cash_time, state, reviewer, reason",
        "from st_cash",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="aid", property="aid", jdbcType=JdbcType.INTEGER),
        @Result(column="cash_money", property="cash_money", jdbcType=JdbcType.DOUBLE),
        @Result(column="cash_time", property="cash_time", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="reviewer", property="reviewer", jdbcType=JdbcType.VARCHAR),
        @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR),
        @Result(column="aid", property="agent", one=@One(select="com.sthz.facepay.mapper.AgentMapper.getById",fetchType = FetchType.EAGER))
    })
    Cash selectByPrimaryKey(Integer id);

    @UpdateProvider(type=CashSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Cash record);

    @Update({
        "update st_cash",
        "set aid = #{aid,jdbcType=INTEGER},",
          "cash_money = #{cash_money,jdbcType=DOUBLE},",
          "cash_time = #{cash_time,jdbcType=TIMESTAMP},",
          "state = #{state,jdbcType=TINYINT},",
          "reviewer = #{reviewer,jdbcType=VARCHAR},",
          "reason = #{reason,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Cash record);
}